package com.googlecode.roleaccesscontrol.wicket.common;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.ListChoice;
import org.apache.wicket.model.ResourceModel;

public class YesNoListChoice extends ListChoice<Boolean> {

	private static final long serialVersionUID = 1L;

	private static final List<Boolean> YES_NO_LIST = Arrays.asList(Boolean.TRUE, Boolean.FALSE);

	public YesNoListChoice(String id) {
		super(id, YES_NO_LIST);
		setMaxRows(1);
		setChoiceRenderer(new IChoiceRenderer<Boolean>() {
			public Object getDisplayValue(Boolean bool) {
				String key = bool.booleanValue() ? "yes" : "no";
				return new ResourceModel(key).wrapOnAssignment(YesNoListChoice.this).getObject();
			}

			public String getIdValue(Boolean bool, int index) {
				return bool.booleanValue() ? "1" : "0";
			}
		});
	}
}
